package com.example.administrator.xxnapp.bean;

import com.example.administrator.xxnapp.fragment.mine.IModelMine;
import com.example.administrator.xxnapp.friend.IModelFriend;
import com.example.administrator.xxnapp.http.HttpUrl;
import com.example.administrator.xxnapp.login.IModelPassword;
import com.example.administrator.xxnapp.user.IModelUser;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.request.GetRequest;
import com.lzy.okgo.request.PostRequest;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Went_Gone on 2018/4/23.
 */

public class UserBean implements IModelMine,Serializable,IModelFriend,IModelPassword,IModelUser{

    /**
     * userId : 1
     * userPhone : 18515573396
     * userName : 王套路
     * gender : 100001
     * age : 23
     */

    private int userId;
    private String userPhone;
    private String userName;
    private String gender;
    private int age;
    /**
     * headImage : http://wentgone.cn/xxn/images/-1befd0f85d8241f5.jpg
     */

    private String headImage;


    @Override
    public PostRequest<String> signIn(String userPhone, String password) {
        JSONObject object = new JSONObject();
        try {
            object.put("userName",userPhone);
            object.put("password",password);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return OkGo.<String>post(HttpUrl.POST_SIGN_IN_URL)
                .upJson(object.toString());
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public String getUserPhone() {
        return userPhone;
    }

    public void setUserPhone(String userPhone) {
        this.userPhone = userPhone;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getHeadImage() {
        return headImage;
    }

    public void setHeadImage(String headImage) {
        this.headImage = headImage;
    }

    @Override
    public GetRequest<String> getFriends(int userId) {
        return OkGo.get(HttpUrl.GET_FRIENDS+"/"+userId);
    }

    @Override
    public PostRequest<String> updatePassword(String phoneNum, String password) {
        return OkGo.<String>post(HttpUrl.POST_UPDATE_PASSWORD)
                .params("username",phoneNum)
                .params("password",password);
    }

    @Override
    public PostRequest<String> uploadHeadImage(File file, int userId) {
        List<File> files = new ArrayList<>();
        files.add(file);
        return OkGo.<String>post(HttpUrl.POST_HEAD_IMAGE+userId)
                .addFileParams("file",files);
    }

    public interface Gender{
        String male = "100001";
        String female = "100002";
    }
}
